#include "buildInDialog.h"

buildInDialog::buildInDialog()
{
	fileBtn = new QPushButton("打开");
	fontBtn = new QPushButton("字体");
	colorBtn = new QPushButton("颜色");
	inputBtn = new QPushButton("保存");
	progressBtn = new QPushButton("关闭");

	textEdit = new QTextEdit();

	QVBoxLayout *rightLay = new QVBoxLayout();
	rightLay->addWidget(fileBtn);
	rightLay->addWidget(fontBtn);
	rightLay->addWidget(colorBtn);
	rightLay->addWidget(inputBtn);
	rightLay->addWidget(progressBtn);

	QHBoxLayout *mainLay = new QHBoxLayout();
	mainLay->addWidget(textEdit);
	mainLay->addLayout(rightLay);

	setLayout(mainLay);
	connect(fileBtn, SIGNAL(clicked()), this, SLOT(slotFile()));
	connect(colorBtn, SIGNAL(clicked()), this, SLOT(slotColor()));
	connect(fontBtn, SIGNAL(clicked()), this, SLOT(slotFont()));
	connect(inputBtn, SIGNAL(clicked()), this, SLOT(slotInput()));
	connect(progressBtn, SIGNAL(clicked()), this, SLOT(slotProgress()));
}

void buildInDialog::slotFile()
{

}








































void buildInDialog::slotFont()
{
	bool ok;
	QFont font = QFontDialog::getFont(&ok);
	if(ok)
		textEdit->setFont(font);

}
void buildInDialog::slotColor()
{
	QPalette palette = textEdit->palette();
	QColor color = QColorDialog::getColor(palette.color(QPalette::Text),  this);
	if(color.isValid())
	{
		palette.setColor(QPalette::Text, color);
		textEdit->setPalette(palette);
	}
}
void buildInDialog::slotInput()
{
	bool ok;
	QString str = QInputDialog::getText(this, "保存文件", "请输入路径", QLineEdit::Normal, "/", &ok);
	QFile file(str);
	QTextStream out(&file);
	QString a = textEdit->toPlainText();
	out<<a<<"\n";
}
void buildInDialog::slotProgress()
{
	QProgressDialog *progress = new QProgressDialog(this);
	progress->setRange(0,100);
	for(int i=0; i<=100; i+=10)
	{
	//	qApp->processEvents();
		progress->setValue(i);
		sleep(1);
	}
	return;
}
